package org.dfg.corejava.designPattern.component;

import java.util.ArrayList;
import java.util.List;

/**
 * 有枝节点
 * @author DingFugui
 */
public class Composite implements Component {
	private String name;

	private List<Component> children = new ArrayList<Component>();

	public Composite(String name) {
		this.name = name;
	}

	@Override
	public void add(Component c) {
		children.add(c);
	}

	@Override
	public void remove(Component c) {
		children.remove(c);
	}

	@Override
	public void show(int i) {
		for (int x = 0; x < i; x++) {
			System.out.print("-");
		}
		System.out.println("枝" + name);
		for (Component c : children) {
			c.show(i + 1);
		}
	}

}
